package com.controller.retrieval;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.table.distance;
import com.util.connection.ConnectionManager;

public class CurveletImageRetrieveNextPage {
	 private HttpServletRequest servletRequest;
	    HttpServletRequest request=ServletActionContext.getRequest();  

		public String execute() {
			 int pageNo= Integer.parseInt((String)request.getParameter("pageNo"));
			 Connection conn = null;
			 Statement stmt = null;
			
			try {
				 conn = ConnectionManager.getConnectionCurvelet();
	             stmt = conn.createStatement();
	             ServletActionContext.getRequest().getSession().setAttribute("current_cur_query", "11202");
	             String max_img_id = (String) ServletActionContext.getRequest().getSession().getAttribute("current_cur_query");
	             String sel_sql = "select data_im_id,distance from cur_pw_mean_std_dist where query_im_id=" +max_img_id + "  order by distance LIMIT  0 , 25";
                 ResultSet rs_img = stmt.executeQuery(sel_sql);
                 ArrayList imgList = new ArrayList();
                 
   		      while(rs_img.next()){
   		    	distance imgDistObj=new distance();
   		    	imgDistObj.setData_im_id(rs_img.getString("data_im_id"));
   		    	imgList.add(imgDistObj);
   		       }
   		      rs_img.close();
   		     request.setAttribute("imgList", imgList);
			}catch(SQLException se){
		         se.printStackTrace();
		     }catch(Exception e){
		        e.printStackTrace();
		     }finally{
		        try{
		           if(stmt!=null)
		              conn.close();
		        }catch(SQLException se){
		        }
		        try{
		           if(conn!=null)
		              conn.close();
		        }catch(SQLException se){
		           se.printStackTrace();
		        }
		     }
		    	return "success";
		}
			
}
